package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zzyl.base.ResponseResult.success;

@RestController
@Slf4j
@RequestMapping("/nursing_project")
@Api(tags = "护理项目")

public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 分页查询护理项目信息
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */

    @GetMapping
    @ApiOperation("分页查询护理项目信息")
    public ResponseResult<PageResponse<NursingProjectVo>> selectByPage(@ApiParam(value = "护理项目名称") String name,
                                                                       @ApiParam(value = "当前页码") @RequestParam(defaultValue = "1",required = false)Integer pageNum,
                                                                       @ApiParam(value = "每页显示条数") @RequestParam(defaultValue = "10",required = false)Integer pageSize,
                                                                       @ApiParam(value = "状态")Integer status){
        PageResponse<NursingProjectVo> pageResponse = nursingProjectService.selectByPage(name, pageNum, pageSize, status);
        return success(pageResponse);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult getById(@PathVariable("id") Long id){
        NursingProjectVo vo = nursingProjectService.getById(id);
        return success(vo);
    }

    @PutMapping()
    @ApiOperation("根据id更新护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    /**
     * 删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult delete(@PathVariable("id") Long id){
        nursingProjectService.delete(id);
        return success();
    }
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult setStatus(@PathVariable("id") Long id , @PathVariable("status")Integer status){
        nursingProjectService.setStatus(id,status);
        return success();
    }

}
